var express = require('express');
var router = express.Router();
var jwt = require('jsonwebtoken')
let UserList = require("../config/form/userInfo")
/* GET home page. */
//增加
router.post('/add', function(req, res, next) {
    try {
        let user = new UserList(req.body)
          user.save((err,success)=>{
            res.json({status:1,message:"添加成功"})
          })
    
      }catch(e){
        console.log(e)
      }
});
// 删除 传入id
router.post('/delete',async function(req, res, next) {
  try {
    await  UserList.deleteOne({_id:req.body.id})
    res.json({status:1,message:"删除成功"})
  }catch(e){
    console.log(e)
  }
});
// 修改 
router.post('/update',async function(req, res, next) {
    try {
        let data =JSON.parse(JSON.stringify(req.body)) 
        delete data.id
      await  UserList.update({"_id":req.body.id},{$set:data})
        res.json({status:1,message:"修改成功"})
    }catch(e){
      console.log(e)
    }
});
// 查询
router.post('/find',async function(req, res, next) {
    try {
        let users = await UserList.find()
        res.json({status:1,users:users,message:"查询成功"})
    }catch(e){
      console.log(e)
    }
});
module.exports = router;
